//
//  JumpView.m
//  Objc进阶Demo
//
//  Created by Don't update on 2018/7/17.
//  Copyright © 2018年 Don't update. All rights reserved.
//

#import "JumpView.h"

@implementation JumpView

-(void)layoutSubviews

{
    
    self.backgroundColor = [UIColor lightGrayColor];
    
    //创建一个按钮
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setTitle:@"跳转" forState:UIControlStateNormal];
    
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    btn.frame = self.bounds;
    
    [btn addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:btn];
    
}

-(void)changeView{
    //找到当前视图所在的控制器
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    //然后再在此处对对应的视图控制器进行操作
    //........例如
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"视图跳转" message:@"测试" preferredStyle:(UIAlertControllerStyleActionSheet)];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:(UIAlertActionStyleDefault) handler:nil];
    [alert addAction:confirm];
    [nav presentViewController:alert animated:YES completion:nil];
}

@end
